package quick.portal.fragment.notice;

import java.util.List;

import com.alibaba.fastjson.JSONArray;

import quick.portal.R;
import quick.portal.data.NoticeInfo;
import quick.portal.fragment.DataListFragment;
import quick.view.quickadapter.BaseAdapterHelper;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.TextView;


public class NoticeFragment extends DataListFragment<NoticeInfo> {
	
	public NoticeFragment() {
		this.queryAction = "NoticeInfoList";
    	this.itemViewLayoutId = R.layout.data_list_item_notice;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		PopupMenu menu = this.GetOriginalPopupMenu();
		//menu.getMenu().add(0,WorkOrderFragment.menu_addworkorder,1,"新建工单");
		menu.setOnMenuItemClickListener(this);
	}
	
    
	@Override
	protected void adapterConvert(BaseAdapterHelper helper, NoticeInfo notice) {
		helper.setText(R.id.name, notice.getName())
        .setTag(R.id.name, notice)
        .setText(R.id.createUserName, notice.getCreateUserName())
		.setText(R.id.approveTime, notice.getApproveTime());
		
		boolean isRead = notice.getIsRead();
		
		if(isRead)
		{
			helper.setTextColorRes(R.id.name, R.color.color_black);
		}
		else
		{
			helper.setTextColorRes(R.id.name, R.color.color_red);
		}
	}

	@Override
	protected void showDetail(View view) {
		TextView tvName = (TextView)view.findViewById(R.id.name);
		NoticeInfo notice = (NoticeInfo)tvName.getTag();

        Intent intent = new Intent(context,NoticeDetailActivity.class);
        intent.putExtra("NoticeInfoId", notice.getId());
        intent.putExtra("IsRead", notice.getIsRead());
        startActivity(intent);
	}

	@Override
	protected List<NoticeInfo> parseArray(String body) {
		List<NoticeInfo> list = JSONArray.parseArray(body, NoticeInfo.class);
		
		return list;
	}

}
